﻿@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "CourseId=" + pageInfo.CourseId;

}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>资源管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">@pageInfo.CourseName<br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 4)
    <div class="container mainwrap">
        <div class="row">
            @Html.Partial("~/Views/Share/PublicResourceInfoMenu.cshtml", this.ViewData)
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <ol class="breadcrumb">
                            <li>资源管理</li>
                            <li class="active">@(ViewData["TypeName"])管理</li>
                        </ol>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <form class="form-horizontal" role="form">
                                <div class="form-group">
                                    <div class="col-xs-4">
                                        <input type="text" class="form-control" id="titleSearchTxt" placeholder="请输入标题">
                                    </div>
                                    <div class=" col-xs-6">
                                        <button type="button" onclick="getList(1)" class="btn btn-success"><span class="glyphicon glyphicon-search"></span>搜索</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <table class="table table-bordered tb1">
                            <thead>
                                <tr>
                                    <th>标题</th>
                                    <th>文件名</th>
                                    <th>创建人</th>
                                    <th>上传时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="tbody">
                            </tbody>
                        </table>
                        <div class="row clearfix well d-page">
                            <div id="PagInfo" class="pull-left sum">
                            </div>
                            <div class="clearfix pull-right">
                                <ul id="PageTool" class="pagination">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")

    <script>
        var tbody = $("#tbody");
        var _courseId = "@ViewData["CourseId"]";
        var options = false;
        var _state = false;
        function getList(pageNo) {

            $("#PagInfo").html("");
            $("#PageTool").html("");

            var _typeCode = $("#resourceInfoList li.active").attr("id");
            var _title = $("#titleSearchTxt").val();
            $.easyPost("/ResourceInfo/GetResourceInfoList", { "PageNO": pageNo, "PageSize": "10", "CourseId": _courseId, "TypeCode": _typeCode, "Title": _title },
               function (data) {
                   if (!data.result) {
                       showTips.open(data.message);
                       return;
                   }
                   var _html = '';
                   if (data.rows.length > 0) {
                       $(".d-page").show();

                       var _row = data.rows,
                           _rowL = _row.length;
                       options = {
                           totalPages: data.totalPage,
                           total: data.total,
                           currentPage: pageNo,
                           onPageClicked: function (event, originalEvent, type, page) {
                               getList(page);
                           }
                       }
                       initialPaginator(options, "PageTool", "PagInfo");

                       for (var i = 0; i < _rowL; i++) {
                           var item = _row[i];
                           var _date = item.CreateTime.toString().replace(/\//g, "");
                           var time = eval('new ' + _date);

                           _html += "<tr>";
                           _html += "<td>" + item.Title + "</td>";
                           _html += "<td>" + item.FileName + "</td>";
                           _html += "<td>" + item.Creator + "</td>";
                           _html += "<td>" + time.format('yyyy-MM-dd') + "</td>";
                           _html += "<td>";
                           _html += "<a href='javascript:void(0)' onclick='del(\"" + item.Id + "\")'><span class='glyphicon glyphicon-trash'></span> 删除</a>";
                           _html += "</td>";
                           _html += "</tr>";
                       }
                   }
                   else {
                       _html = "<tr><td colspan='5' align='center'>暂无内容!</tr>";
                       $(".d-page").hide();
                   }
                   tbody.html(_html);
               }, "json");
        }


        if (!!window.location.hash) {
            var _hash = window.location.hash.substr(1);
            getList(_hash);
        } else {
            getList(1);
        }


        //删除
        function del(id) {
            $.easyPost("/ResourceInfo/ResourceInfoDel", { "Id": id },
              function (data) {
                  if (!data.result) {
                      showTips.open(data.message);
                      return;
                  }
                  getList(1);
              }, "json");
        }
    </script>
</body>
</html>
